package com.leyou.item.controller;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父分类ID查询子分类列表
     */
    @GetMapping("of/parent")
    public ResponseEntity<List<CategoryDTO>> queryByParentId(@RequestParam("pid") Long pid){
        return ResponseEntity.ok(categoryService.queryByParentId(pid));
    }

    /**
     * 根据品牌查询商品分类
     */
    @GetMapping("of/brand")
    public ResponseEntity<List<CategoryDTO>> queryByBrandId(@RequestParam("id") Long brandId) {
        return ResponseEntity.ok(categoryService.queryByBrandId(brandId));
    }
}
